#include <iostream>
#include <vector>
#include <assert.h>

using namespace std;

class BitVector {
    vector<unsigned> store_;
    enum { bits =  (sizeof(unsigned)*8) };

    static unsigned roundup( unsigned n, unsigned align ) {
	return (n + align - 1) & ~(align-1);
    }
  public:
    BitVector( unsigned size ) 
	    : store_( roundup ( size/bits, bits ), 0 ) {
    }
    void set( unsigned i ) {
	store_[i/bits] |= 1<<(i%bits);
    }
    void reset( unsigned i ) {
	store_[i/bits] &= ~(1<<(i%bits));
    }
    bool get( unsigned i ) {
	return store_[i/bits] & (1<<(i%bits));
    }
};

void test_bit( BitVector &v, unsigned val ) {
    assert( !v.get(val) );
    v.set(val);
    assert( v.get(val) );
    v.reset(val);
    assert( !v.get(val) );
}

int main( int argc, char* argv[] ) {

    BitVector v(1023);
    for ( unsigned i = 0; i<1023; i++ ) {
    	test_bit( v, i );
    }
    return 0;
}
